package com.yangchao.groovy.ch03

class example16 {
    static void main(String[] args) {
        def teacher = new Teacher("李晓");
        teacher.vistor();
        teacher.walk();
    }
}

// 接口
interface Visitor {
    def vistor() // 访问
}

// 人（抽象类，实现了Visitor接口）
abstract class Person implements Visitor {
    String name
    int age

    @Override
    def vistor() {
        println this.name + "出去访问了"
    }

    abstract walk() // 散步
}

// 老师（继承）
class Teacher extends Person {
    // 家庭
    private Family family

    Teacher(String name, int age = 30){
        this.name = name
        this.age = age
        this.family = new Family()
    }

    @Override
    def walk() {
        println this.name + "散步去了"
    }

    @Override
    def vistor(){
        // println this.name + "出去购物了"
        this.family.goHome()
    }

    def goHomeEx() {
        println this.name + "回家了"
    }

    /** 内部类 */
    private class Family {
        def goHome() {
            goHomeEx()
        }
    }
}  